const util = require('./util.js')
const baseurl = util.baseurl

export { getVolunteerActivityList, getVolunteerActivityDetail, addVolunteerActivity }


//获取志愿者活动列表
const getVolunteerActivityList = () => {
    return new Promise((resolve, reject) => {
        const userInfo = wx.getStorageSync('userInfo')
        wx.request({
            url: baseurl + '/VolunteerActivity/GetVolunteerActivityList',
            method: 'GET',
            header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Username': userInfo.username,
                'Authorization': userInfo.token,
                'Userrole': userInfo.role,
                'Uid': userInfo.userid
            },
            success: (res) => {
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
//获取志愿者活动详情
const getVolunteerActivityDetail = (id) => {
    return new Promise((resolve, reject) => {
        const userInfo = wx.getStorageSync('userInfo')
        wx.request({
            url: baseurl + '/VolunteerActivity/GetVolunteerActivity',
            method: 'GET',
            header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Username': userInfo.username,
                'Authorization': userInfo.token,
                'Userrole': userInfo.role,
                'Uid': userInfo.userid
            },
            data: {
                "id": id
            },
            success: (res) => {
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
//添加志愿者活动
const addVolunteerActivity = (data) => {
    return new Promise((resolve, reject) => {
        const userInfo = wx.getStorageSync('userInfo')
        wx.request({
            url: baseurl + '/VolunteerActivity/EnrollVolunteerActivity',
            method: 'POST',
            header: {
                'content-type': 'application/json',
                'Username': userInfo.username,
                'Authorization': userInfo.token,
                'Userrole': userInfo.role,
                'Uid': userInfo.userid
            },
            data: {
                "Duration": data.startTime,
                "Hour": data.duration,
                "Content": data.serviceContent,
                "Feedback": data.familyFeedback,
                "Experience": data.volunteerExperience
            },
            success: (res) => {
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
